class Product < ActiveRecord::Base
  attr_accessible :description, :image_url, :name, :product_type, :available, :orginal_price

  has_many :line_items
  has_many :carts, :through => :line_items
  def self.search(type, key)
    if type && type != ''
      if key && key != ''
        find(:all, :conditions => ['product_type = ? AND name LIKE ?', "#{type}", "%#{key}%"])
      else
        find(:all, :conditions => ['product_type = ?', "#{type}"])
      end
    elsif key && key != ''
      find(:all, :conditions => ['name LIKE ?', "%#{key}%"])
    else
      find(:all)
    end
  end
end
